<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      #canvas {
        border: 1px solid;
      }
    </style>
  </head>

  <body>
    <canvas width="400" height="400" id="canvas"> 请升级你的服务器 </canvas>
    <script>
      var canvas = document.querySelector("#canvas");
      var context = canvas.getContext("2d");

      context.font = "50px sans-serif";
      context.textAlign = "center";
      context.textBaseline = "middle"; // 基线
      context.direction = "rtl";
      var linear = context.createLinearGradient(0, 0, 400, 0);
      linear.addColorStop(0, "blue");
      linear.addColorStop(0.5, "yellow");
      linear.addColorStop(1, "red");
      context.fillStyle = linear;
      context.fillText("中国队加油！", 200, 200);
      var x = 0;
      setInterval(function () {
        // context.clearRect(0, 0, 400, 400);
        x += 5;
        if (x > 400) {
          x = -400;
        }
        linear = context.createLinearGradient(x, 0, 400 + x, 0);
        linear.addColorStop(0, "blue");
        linear.addColorStop(0.5, "yellow");
        linear.addColorStop(1, "red");
        context.fillStyle = linear;
        context.fillText("中国队加油！", 200, 200);
      }, 17);
      //   var linear = context.createLinearGradient(0, 0, 400, 0);
      //   linear.addColorStop(0, "blue");
      //   linear.addColorStop(0.5, "yellow");
      //   linear.addColorStop(1, "red");

      //   context.fillStyle='#f00';
    </script>
  </body>
</html>
